<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page language="java" import="java.sql.*" %>


<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<SCRIPT LANGUAGE="JavaScript">

function voce(livello,nome,link,icona,foglia) {
  this.livello = livello;
  this.nome = nome;
  this.link = link;
  this.icona = icona;
  this.foglia = foglia;
}



var elemento = new Array()
var i = 0;

elemento[++i] = new voce(0,'Procedure','','',false);

<%

String sql;
ResultSet rs;


//caricamento driver
//Class.forName("com.mysql.jdbc.Driver");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//apertura connessione
//Connection cn = DriverManager.getConnection("jdbc:mysql://192.168.0.3/test?user=test&password=test");

Connection cn = DriverManager.getConnection ("jdbc:microsoft:sqlserver://ormt189:1433;DatabaseName=Procedure_rmreps;user=test;password=test");

Statement stmt = cn.createStatement();
Statement stmt1 = cn.createStatement();
sql="SELECT categoria.nome, categoria.id_categoria from categoria order by nome";


ResultSet rs_categorie = stmt.executeQuery(sql);
while(rs_categorie.next()) {
%>

elemento[++i] = new voce(1,'<%=rs_categorie.getString("nome")%>','','',false);

<%

sql= "SELECT procedura.titolo, procedura.id_procedura from procedura where id_categoria=" + rs_categorie.getString("id_categoria") + " and stato=0";

ResultSet rs_procedure = stmt1.executeQuery(sql);
while(rs_procedure.next()) {
%>



<%-- elemento[++i] = new voce(2,'<%=rs_procedure.getString("titolo")%>','visualizza_procedura.asp?id_procedura=<%=rs_procedure.getString("id_procedura")%>','',true); --%>
elemento[++i] = new voce(2,'<%=rs_procedure.getString("titolo")%>','visualizza_procedura.jsp?id_procedura=<%=rs_procedure.getString("id_procedura")%>','',true);

<%

}

}
%>

elemento[++i] = new voce(1,'','','images/logo.gif',true);




var nascosto = new Array();

for (c=1;c<=i;c++) {
  if (elemento[c].livello==1) nascosto[c] = false;
  else nascosto[c] = true;
}

function disegna() {
  var code = '';
  code += '<TABLE BORDER=0><TR><TD NOWRAP>';
  code += '<A HREF="' + elemento[1].link + '" TARGET="main" class="scritta_banner">';
  if (elemento[1].icona=='') code += '<IMG SRC="images/home.gif" BORDER=0>';
  else code += '<IMG SRC="' +  elemento[1].icona + '" BORDER=0>';
  code += '<font class="scritta_banner">' + elemento[1].nome + '</font></A><BR>';
  for (c=2;c<=i;c++) {
    if (!nascosto[c]) {
       var app = elemento[c];
       for (k=2;k<=app.livello;k++) code += '<IMG SRC="images/i.gif" BORDER=0>';
       if (app.foglia) {
         if (c!=i && app.livello==elemento[c+1].livello) code += '<IMG SRC="images/t.gif" BORDER=0>';
         else code += '<IMG SRC="images/l.gif" BORDER=0>';
         if (app.icona=='') app.icona = 'images/members.gif';
         if (app.icona=='images/members.gif') code += '<A HREF="' + app.link + '" TARGET="principale" class="scritta_banner">';
         code += '<IMG SRC="' + app.icona + '" BORDER=0>&nbsp;';
       } else {
         if (nascosto[c+1]) code += '<A HREF="javascript: apri(' + c + ')"><IMG SRC="images/xl.gif" BORDER=0 class="scritta_banner"></A><IMG SRC="images/cartella1.gif"  BORDER=0>&nbsp;';
         else code += '<A HREF="javascript: chiudi(' + c + ')" class="scritta_banner"><IMG SRC="images/-l.gif" BORDER=0 class="scritta_banner"><IMG SRC="images/cartella2.gif"  BORDER=0>&nbsp;';
       }
       code += '<font class="scritta_banner">' + app.nome + '</font></A><BR>';
    }
  }
  code += '</TD></TR></TABLE>';
  if (document.all) esplora.innerHTML = code;
  else {
    document.layers.esplora_nn.document.open();
    document.layers.esplora_nn.document.write(code);
    document.layers.esplora_nn.document.close();
  }
}


function apri(n) {
  var c = n + 1;
  while (elemento[c].livello>elemento[n].livello) c++;
  for(k=n+1;k<c;k++) if (elemento[k].livello==elemento[n].livello + 1) nascosto[k] = false;
  disegna();
}

function chiudi(n) {
  var c = n + 1;
  while (elemento[c].livello>elemento[n].livello) c++;
  for(k=n+1;k<c;k++) nascosto[k] = true;
  disegna();
}

</SCRIPT>

<STYLE>
<!--
A {text-decoration: none; color: black}
A:hover {color: red}
-->
</STYLE>

<BODY ONLOAD="disegna()" BGCOLOR="#999999">
<TABLE  BORDER=0 CELLSPACING=0 CELLPADDING=0  BGCOLOR="#999999">
	<TR height=100%>
		<TD valign=top>&nbsp;
			<LAYER NAME="esplora_nn">
			</LAYER>

			<DIV ID="esplora">
			</DIV>
		</TD>
	</TR>
</TABLE>

</BODY>
</HTML>

<%
stmt.close();
cn.close();
%>